﻿Imports CodeCounter.Library
Imports System.IO

Namespace VBCodeCountingLogic


    ''' <summary>
    ''' This example shows how the ICodeCounterLogic is implemented to count VB.NET code.   Just for kicks
    ''' it just happens to be implemented in VB.NET
    ''' </summary>
    ''' <remarks></remarks>
    Public Class VBCodeCountingLogicImp
        Implements ICodeCounterLogic

        ''' <summary>
        ''' This is the main logic.   It examines a line and returns the results of that examination
        ''' </summary>
        ''' <param name="line">string</param>
        ''' <returns>CodeCounterLineType</returns>
        ''' <remarks></remarks>
        Public Function LineType(ByVal line As String) As CodeCounterLineType Implements ICodeCounterLogic.LineType
            LineType = CodeCounterLineType.EmptyLine

            Dim trimmedLine As String
            trimmedLine = line.Trim()
            If (True = trimmedLine.StartsWith("'")) Then
                LineType = CodeCounterLineType.CommentOnly
            ElseIf (0 = trimmedLine.Length) Then
                LineType = CodeCounterLineType.EmptyLine
            ElseIf (True = trimmedLine.Contains("'")) Then
                LineType = CodeCounterLineType.StatementAndComment
            Else
                LineType = CodeCounterLineType.Statement
            End If
        End Function
        ''' <summary>
        ''' Evaluates the file name, if it has a VB extension we consider it something we can work with
        ''' </summary>
        ''' <param name="file">string</param>
        ''' <returns>bool</returns>
        ''' <remarks></remarks>
        Function CanProcessFile(ByVal file As String) As Boolean Implements ICodeCounterLogic.CanProcessFile
            Dim fileInfo As FileInfo
            fileInfo = New FileInfo(file)
            If (".VB" = fileInfo.Extension.ToUpper()) Then CanProcessFile = True Else CanProcessFile = False
        End Function
        ''' <summary>
        ''' The engine can determine a blank line (the engine says a line of 0 lenth (excluding spaces) is blank)
        ''' </summary>
        ''' <returns>always returns true</returns>
        ''' <remarks></remarks>
        Function EngineCanDetermineBlankLines() As Boolean Implements ICodeCounterLogic.EngineCanDetermineBlankLines
            EngineCanDetermineBlankLines = True
        End Function

        ''' <summary>
        ''' Returns an array of the file types we can process
        ''' </summary>
        ''' <returns>string array:  1 element containing VB</returns>
        ''' <remarks></remarks>
        Function FileTypesHandled() As String() Implements ICodeCounterLogic.FileTypesHandled
            Dim typesSupported(0) As String
            typesSupported(0) = "VB"
            FileTypesHandled = typesSupported
        End Function

        ''' <summary>
        ''' empty implementation, required by interface but unused by us
        ''' </summary>
        ''' <param name="fileName">ignored</param>
        ''' <remarks></remarks>
        Sub PostfileProcessing(ByVal fileName As String) Implements ICodeCounterLogic.PostfileProcessing

        End Sub
        ''' <summary>
        ''' empty implementation, required by interface but unused by us
        ''' </summary>
        ''' <param name="fileName">ignored</param>
        ''' <remarks></remarks>
        Sub PrefileProcessing(ByVal fileName As String) Implements ICodeCounterLogic.PrefileProcessing

        End Sub

    End Class
End Namespace